package com.soft.mapper;
import java.util.List;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.soft.entity.User;
@SpringBootTest
public class UserMapperTest {
	@Autowired
	private UserMapper userMapper;
	//@Test
	public void insertTest() {
		User user = new User();
		user.setUserName("111");
		user.setUserAge("18");
		user.setUserEmail("5sss5@5ss.com");
		userMapper.insert(user);
	}
	//@Test
	public void deleteTest() {
		User user = new User();
		user.setUserId(3l);
		userMapper.deleteById(user);
	}
	//@Test
	public void updateTest() {
		User user = new User();
		user.setUserId(4l);
		user.setUserName("王五");
		user.setUserAge("30");
		userMapper.updateById(user);
	}
	@Test
	public void updateQueryTest() {
		UpdateWrapper<User> uw = new UpdateWrapper<>();
		uw.gt("id", 2);
		User user = new User();
		user.setUserEmail("11111@1111.com");
		userMapper.update(user,uw);
	}
	//@Test
	public void testSelect() {
		List<User> userList = userMapper.selectList(null);
		for(int i=0;i<userList.size();i++) {
			System.out.println(userList.get(i).getUserId());
			System.out.println(userList.get(i).getUserName());
			System.out.println(userList.get(i).getUserAge());
			System.out.println(userList.get(i).getUserEmail());
		}
	}
	@Test
	public void selectIdTest() {
		User user = userMapper.selectById(8);
		System.out.println(user.getUserName());
	}@Test
	public void selectOneTest() {
		QueryWrapper<User> qw = new QueryWrapper<>();
		qw.gt("id", 1);
		try {
		User user = userMapper.selectOne(qw);
		System.out.println(user);
		}catch(Exception e) {
			System.out.println("用户名或密码重复，请修改密码");
		}
	}
	//@Test
	public void deleteQueryTest() {
		QueryWrapper<User> qw = new QueryWrapper<>();
		qw.eq("user_name", "111");
		userMapper.delete(qw);
	}
}
